<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta http-equiv="Cache-Control"  content="no-transform">
    <meta http-equiv="content-type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
    <title>商家中心</title>
    <link href="/statics/bootstrap/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
    <link href="/statics/metisMenu/metisMenu.min.css" rel="stylesheet">
    <link href="/statics/font-awesome/css/font-awesome.min.css" rel="stylesheet">
    <link href="/statics/sb/css/sb-admin-2.css" rel="stylesheet">
    <link href="/statics/view/css/all.css" rel="stylesheet">
    <script src="/statics/jquery/jquery.min.js"></script>
    <!--[if lt IE 9]>
    <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
    <script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
    <style type="text/css"> </style>
</head>
<body>
<div id="wrapper">
    [#include "/bcenter/include/header.ftl" /]

    <!-- Page Content -->
    <div id="page-wrapper" style="min-height: 513px;">
        <div class="row">
            <div class="col-lg-12">
                <h1 class="page-header">商品编辑</h1>
            </div>
        </div>
        <div class="row">
            <div class="col-lg-12">
                <div class="panel panel-default">
                    <div class="panel-heading">
                        商品编辑
                    </div>
                    <div class="panel-body">
                        <form action="update" method="post" id="inputForm" class="form-horizontal"   enctype="multipart/form-data" onsubmit="return validateForm(this)">
                            <input type="hidden" name="id" value="${entity.id}"/>
                            <ul class="nav nav-tabs">
                                <li class="active"><a href="#home" data-toggle="tab" aria-expanded="false">基本信息</a>
                                </li>
                                <li class=""><a href="#profile" data-toggle="tab" aria-expanded="false">商品详情</a>
                                </li>
                                <li class=""><a href="#messages" data-toggle="tab" aria-expanded="true">商品相册</a>
                                </li>
                            </ul>
                            <div class="tab-content">
                                <div class="tab-pane fade  active in" id="home">
                                    <div class="col-lg-6" style="margin-top: 20px;">
                                        <div class="form-group">
                                            <label class="control-label col-sm-3">SN编号</label>
                                            <div class="col-sm-5">
                                                <input type="text" name="sn" value="${entity.sn}" class="form-control" disabled="disabled" placeholder="系统将自动生成">
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label class="control-label col-sm-3">商品名称</label>
                                            <div class="col-sm-6">
                                                <input type="text" name="name" value="${entity.name}" class="form-control required" minlength="5" placeholder="5-20个汉字或者字母" maxlength="20">
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label class="control-label col-sm-3">商品名称(全名)</label>
                                            <div class="col-sm-9">
                                                <input type="text" name="fullName" value="${entity.fullName}" class="form-control required" minlength="10" placeholder="10-30个汉字或者字母" maxlength="30">
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label class="control-label col-sm-3">销售价</label>
                                            <div class="col-sm-3">
                                                <div class="input-group">
                                                    <input type="text" name="price" class="form-control required number"  value="${entity.price}" placeholder="">
                                                    <span class="input-group-addon" >元</span>
                                                </div>
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label class="control-label col-sm-3">市场价</label>
                                            <div class="col-sm-3">
                                                <div class="input-group">
                                                    <input type="text" name="marketPrice" class="form-control required number" value="${entity.marketPrice}"  placeholder="">
                                                    <span class="input-group-addon" >元</span>
                                                </div>
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label class="control-label col-sm-3">成本价</label>
                                            <div class="col-sm-3">
                                                <div class="input-group">
                                                    <input type="text" name="cost" class="form-control required number" value="${entity.cost}"  placeholder="">
                                                    <span class="input-group-addon" >元</span>
                                                </div>
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label class="control-label col-sm-3">单位</label>
                                            <div class="col-sm-3">
                                                <input type="text" name="unit" class="form-control required" value="${entity.unit}"  placeholder="">
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label class="control-label col-sm-3">重量</label>
                                            <div class="col-sm-4">
                                                <div class="input-group">
                                                    <input type="text" name="weight" class="form-control required" value="${entity.weight}" placeholder="">
                                                    <span class="input-group-addon" >千克(KG)</span>
                                                </div>
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label class="control-label col-sm-3">库存</label>
                                            <div class="col-sm-3">
                                                <input type="text" name="stock" class="form-control required" value="${entity.stock}"  placeholder="">
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label class="control-label col-sm-3">已分配库存</label>
                                            <div class="col-sm-3">
                                                <input class="form-control required" type="text" name="allocatedStock" value="${entity.allocatedStock}" placeholder="">
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label class="control-label col-sm-3">库存备注</label>
                                            <div class="col-sm-3">
                                                <input class="form-control" type="text" name="stockMemo" value="${entity.stockMemo}" placeholder="">
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label class="control-label col-sm-3">上架</label>
                                            <div class="col-sm-3">
                                                <select class="form-control" name="isMarketable" type="text">
                                                    <option value="1" [#if entity.isMarketable=true] selected="selected"[/#if]>是</option>
                                                    <option value="0" [#if entity.isMarketable=false] selected="selected"[/#if]>否</option>
                                                </select>
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label class="control-label col-sm-3">列出</label>
                                            <div class="col-sm-3">
                                                <select class="form-control" name="isList" type="text">
                                                    <option value="1" [#if entity.isMarketable=true] selected="selected"[/#if]>是</option>
                                                    <option value="0" [#if entity.isMarketable=false] selected="selected"[/#if]>否</option>
                                                </select>
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label class="control-label col-sm-3">置顶</label>
                                            <div class="col-sm-3">
                                                <select class="form-control" name="isTop" type="text">
                                                    <option value="1" [#if entity.isMarketable=true] selected="selected"[/#if]>是</option>
                                                    <option value="0" [#if entity.isMarketable=false] selected="selected"[/#if]>否</option>
                                                </select>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                                <div class="tab-pane fade" id="profile" style="padding: 10px;">
                                    <textarea id="editor" name="introduction" class="editor" style="margin-top: 20px;width: 80%;">${entity.introduction}</textarea>
                                </div>
                                <div class="tab-pane fade  " id="messages">
                                    <button class="btn btn-primary btn_addImage" style="margin-top: 20px;">新增</button>
                                    <table class="table table-bordered"  style="margin-top: 20px;">
                                        <thead>
                                        <tr>
                                            <th>图片</th>
                                            <th>标题</th>
                                            <th>排序</th>
                                            <th>操作</th>
                                        </tr>
                                        </thead>
                                        <tbody id="imageTable">
                                        [#list entity.productImages as productImage]
                                        <tr>
                                            <td>
                                                <input type="hidden" name="productImages[${productImage_index}].source" value="${productImage.source}" />
                                                <input type="hidden" name="productImages[${productImage_index}].large" value="${productImage.large}" />
                                                <input type="hidden" name="productImages[${productImage_index}].medium" value="${productImage.medium}" />
                                                <input type="hidden" name="productImages[${productImage_index}].thumbnail" value="${productImage.thumbnail}" />
                                                <input type="file" name="productImages[${productImage_index}].file" class="productImageFile ignore" />
                                                <a href="${productImage.large}" target="_blank">[查看大图]</a>
                                                <a href="${productImage.medium}" target="_blank">[查看中图]</a>
                                                <a href="${productImage.thumbnail}" target="_blank">[查看小图]</a>
                                            </td>
                                            <td>
                                                <input type="text" name="productImages[${productImage_index}].title" class="form-control" maxlength="200" value="${productImage.title}" />
                                            </td>
                                            <td>
                                                <input type="text" name="productImages[${productImage_index}].order" class="form-control productImageOrder" value="${productImage.order}" maxlength="9" style="width: 50px;" />
                                            </td>
                                            <td>
                                                <a href="javascript:;" class="deleteProductImage" id="delImageTrButton${productImage_index}">[删除]</a>
                                            </td>
                                        </tr>
                                        [/#list]
                                    </table>
                                </div>
                                <div class="form-group">
                                    <div class="col-sm-offset-3 col-sm-10">
                                        <button type="submit" class="btn btn-success">提交</button>
                                    </div>
                                </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
</div>
</div>
<script src="/statics/jquery/jquery.validate.js"></script>
<script src="/statics/editor/kindeditor.js"></script>
<script src="/statics/view/js/common.js"></script>
<script src="/statics/bootstrap/js/bootstrap.min.js"></script>
<script src="/statics/metisMenu/metisMenu.min.js"></script>
<script src="/statics/sb/js/sb-admin-2.js"></script>
<script type="text/javascript">
    var productImageIndex=${entity.productImages?size};
    $(function(){
        $(".btn_addImage").click(function() {
            if(productImageIndex>=5){
                return false;
            }
            var trHtml ='<tr>'+
                    '<td>'+
                    '<input type="file" name="productImages['+productImageIndex+'].file" class="form-control"/>'+
                    '</td>'+
                    '<td>'+
                    '<input type="text" name="productImages['+productImageIndex+'].title" class="form-control" maxlength="200"/>'+
                    '</td>'+
                    '<td>'+
                    '<input type="text" name="productImages['+productImageIndex+'].order" class="form-control" maxlength="9" style="width: 50px;"/>'+
                    '</td>'+
                    '<td>'+
                    '<a href="javascript:;" class="deleteProductImage" id="delImageTrButton'+productImageIndex+'">[删除]</a>'+
                    '</td>'+
                    '</tr>';
            $("#imageTable").append(trHtml);
            initProductDelFun();
            productImageIndex ++;
            return false;
        });
    });

    initProductDelFun();


    function initProductDelFun(){
        $(document).on("click","#delImageTrButton"+productImageIndex ,function() {
            var $this = $(this);
            $.dialog({
                type: "warn",
                title:"操作",
                content: "确认删除吗?",
                onOk: function() {
                    $this.closest("tr").remove();
                }
            });
        });
    }
</script>
</body>
</html>